#!/bin/sh

# 错误检查
set -e

# 检查是否已经安装 Docker
if !(command -v docker &> /dev/null)
then
    echo "Docker is not installed. Installing Docker..."
    sudo apt-get update
    sudo apt-get install -y docker.io
    echo "Docker has been installed."
    docker -v
else
    echo "Docker is already installed. Docker version:"
    docker --version
fi

# 检查是否已经安装 Docker Compose
if !(command -v docker-compose &> /dev/null)
then
    echo "Docker Compose is not installed. Installing Docker Compose..."
    apt install -y curl
    # 下载 Docker Compose 的二进制文件
    wget -qO /usr/bin/docker-compose https://gitee.com/kelc/release/raw/master/docker/docker-compose.zip
    # 添加可执行权限
    sudo chmod +x /usr/bin/docker-compose
    echo "Docker Compose has been installed."
    docker-compose -v
else
    echo "Docker Compose is already installed. Docker Compose version:"
    docker-compose -v
fi

ln -sf /usr/bin/docker-compose /usr/bin/dc
echo "配置alias dc=docker-compose: $(dc -v)"
echo prepare.sh done